package com.smarthealthring.mm.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by hewei26 on 2017/4/24.
 */

public class SPUtils {

    private static SharedPreferences spf;
    private static SharedPreferences.Editor editor;

    public static String SP_NAME = "RINGTRIP";

    public static final String TOKEN ="token";
    public static final String USERID ="userId";
    public static final String USERNAME ="userName";

    // 设备相关信息
    public static final String BOND_STATE ="bondState"; // 绑定状态 1绑定 0未绑定
    public static final String IS_FIRST_BOND ="isFirstBond"; // 首次绑定
    public static final String DEVICE_MAC ="deiceMac";
    public static final String DEVICE_NAME ="deviceName";
    public static final String DEVICE_RSSI ="deviceRssi"; //信号强度
    public static final String DEVICE_VERSION ="deviceVersion"; //固件版本
    public static final String DEVICE_POWER ="devicePower"; //电量
    public static final String SPORT_TARGET ="sportTarget"; //运动目标
    public static final String WEIGHT_TARGET ="weightTarget"; //体重目标
    public static final String DEVICE_LAN ="deviceLan";

    // 首页SyncDatabean
    public static final String SYNC_DATA_BEAN ="syncDataBean";
    public static final String LAST_HR ="lastHr";

    // 设置
    public static final String IS_GET_MSG ="isGetMsg";
    public static final String IS_NOT_DISTURBB ="isNotDisturb";
    public static final String NOT_DISTURBB_TIME ="notDisturbTime";
    public static final String IS_FIRST_LOGIN ="isFirstLogin";

    // 用户信息
    public static final String USER_NICK_NAME ="userNickName";
    public static final String USER_SEX ="userSex";
    public static final String USER_BIRTH ="userBirth";
    public static final String USER_HEIGHT ="userHeight";
    public static final String USER_WEIGHT ="userWeight";
    public static final String USER_PHOTO_URL ="userPhotoUrl";

    private SPUtils() {
        // Utility class.
    }

    public static void init(Context context) {
        if (spf == null) {
            spf = context.getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
            editor = spf.edit();
        }
    }

    public static void setInt(String key, int value) {
        editor.putInt(key, value).apply();
    }

    public static int getInt(String key, int defVale) {
        return spf.getInt(key, defVale);
    }

    public static void setString(String key, String value) {
        editor.putString(key, value).apply();
    }

    public static String getString(String key, String defVale) {
        return spf.getString(key, defVale);
    }

    public static void setBoolean(String key, boolean value) {
        editor.putBoolean(key, value).apply();
    }

    public static boolean getBoolean(String key, boolean defVale) {
        return spf.getBoolean(key, defVale);
    }

    public static void setLong(String key, long value) {
        editor.putLong(key, value).apply();
    }

    public static long getLong(String key, long value) {
        return spf.getLong(key, value);
    }

    public static void setFloat(String key, float value) {
        editor.putFloat(key, value).apply();
    }

    public static float getFloat(String key, float defVale) {
        return spf.getFloat(key, defVale);
    }


}
